<template>

	<view>
		<view class="index" style="position: sticky; top: 0; z-index: 1;">
			<uni-section :title="'查询日期'" type="line"></uni-section>
			<view class="example-body">
				<uni-datetime-picker v-model="range" type="daterange" />
			</view>
		</view>
		<record-list :list="list" :button="buttonList" :border="true" @click="clickMethod" @change="changeMethod">
		</record-list>
	</view>
</template>

<script>
	import {
		getRecord,
		getInfo,
		deleteMyPd
	} from "@/api/pd/pd"
	export default {
		data() {
			return {
				range: [],
				queryParams: {
					pageNum: 1,
					pageSize: 9,
				},
				list: [],
				total: null,
				buttonList: [{

					title: '删除',
					background: '#fe5869'
				}, ]
			};
		},
		onLoad() {
			// this.getCurrentMonthFirst();
			this.getmoney()
		},
		methods: {
			// getCurrentMonthFirst() {
			// 	var date = new Date();
			// 	date.setDate(1);
			// 	this.range[0] = date.toISOString().slice(0, 10)
			// 	this.range[1] = new Date().toISOString().slice(0, 10)
			// 	this.getmoney()
			// },
			getmoney() {
				this.queryParams.params = {};
				if (undefined != this.range[0]) {
					this.queryParams.params["beginCreateTime"] = this.range[0];
					this.queryParams.params["endCreateTime"] = this.range[1];

				}
				getRecord(this.queryParams).then(res => {
					for (let i = 0; i < res.rows.length; i++) {
						if (res.rows[i].pay.payUrl == null) {
							res.rows[i].pay.payUrl = "/static/images/notFond.jpg"
						}
						this.$set(res.rows[i], "id", i + 1)
						this.$set(res.rows[i], "isShare", true)
						this.$set(res.rows[i], "slide_x", 0)
					}
					this.list = [...this.list, ...res.rows];
					this.total = res.total;
				})
			},
			clickMethod(event) {

				getInfo(event.payId).then((res) => {
					uni.navigateTo({
						url: '/pages/home/campusFees-details/index?item=' + encodeURIComponent(JSON
							.stringify(event.pay)) + "&&status=" + encodeURIComponent(JSON
							.stringify(res.data.status)) + "&&type=0"
					})
				})
			},
			changeMethod(data, button, index) {
				let self = this
				uni.showModal({
					title: '',
					content: '确定要删除该信息吗？',
					confirmText: '删除',
					confirmColor: '#ff3b32',
					success: function(res) {
						if (res.confirm) {
							// console.log('用户点击确定')
							deleteMyPd(data.pdId).then((res) => {
								for (let i = 0; i < self.list.length; i++) {
									if (self.list[i].pdId == data.pdId) {
										self.list.splice(i, 1)
									}
								}
							})
							uni.showToast({
								icon: "success",
								title: '操作成功!',
								duration: 2000
							});
						} else if (res.cancel) {
							// console.log('用户点击取消')
						}
					}
				})
			},
		},
		watch: {
			range() {
				this.queryParams.params = {};
				if (undefined != this.range[0]) {
					this.queryParams.params["beginCreateTime"] = this.range[0];
					this.queryParams.params["endCreateTime"] = this.range[1];

				}
				this.list = []
				this.queryParams.pageNum = 1
				this.queryParams.pageSize = 9
				getRecord(this.queryParams).then(res => {
					for (let i = 0; i < res.rows.length; i++) {
						if (res.rows[i].pay.payUrl == null) {
							res.rows[i].pay.payUrl = "/static/images/notFond.jpg"
						}
						this.$set(res.rows[i], "id", i + 1)
						this.$set(res.rows[i], "isShare", true)
						this.$set(res.rows[i], "slide_x", 0)
					}
					this.list = [...this.list, ...res.rows];
					this.total = res.total;
				})
			}
		},
		onReachBottom() { //触底事件
			if (this.queryParams.pageNum * this.queryParams.pageSize >= this.total) {
				uni.showToast({
					title: '没有更多数据了',
					icon: 'none',
					duration: 1000
				});
				setTimeout(() => {
					uni.hideLoading()
				}, 500)
			} else {
				if (this.queryParams.pageNum <= this.queryParams.pageNum - 1) {
					setTimeout(() => {
						uni.hideLoading()
					}, 500)
				} else {
					uni.showLoading({
						title: '加载中'
					});
					this.queryParams.pageNum++

					this.getmoney()
				}
				setTimeout(() => {
					uni.hideLoading()
				}, 500)
			}

		},
	}
</script>

<style lang="scss">

</style>
